<?php
class Manage_notifications extends CI_Model {

    function __construct(){
        parent::__construct();
    }
    function getNotifications($user_id){
        $data = array(
          'user_id_to' => $user_id,
        );
        $update = array(
          'user_id_to' => $user_id,
          'status' => "new",
        );
        $status = array(
          'status' => "read"
        );
        
        $notifications =  $this->mongo_db->where($data)->order_by(array('timestamp' => 'DESC'))->get('notifications');
        $this->mongo_db->where($update)->set($status)->update_all('notifications');
        return $notifications;
    }
   function manageNotification($user_id,$id,$media,$uploaded_at,$timestamp,$action,$identifier){
        $userInfos = $this->get_profile_infos->getInfosID($user_id);
        if($media[0]['user_id'] !== $user_id){
            $notification = array(
                $identifier.'_id' => $id,
                'user_id_from' => $user_id,
                'user_name_from' => $userInfos['first_name'] . " " . $userInfos['last_name'],
                'username' => $userInfos['username'],
                'user_from_thumb' => $userInfos['profile_pic_thumb'],
                'user_id_to' => $media[0]['user_id'],
                'thumb' => $media[0]['thumb'],
                'identifier' => $identifier,
                'action' => $action,
                'uploaded_at' => $uploaded_at,
                'timestamp' => $timestamp,
                'status' => 'new',
            );
            return $this->mongo_db->insert('notifications', $notification);
        }else{
            return true;
        }
        
    }
}
?>